<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册</title>
    {{include '../shared/_header'}}
</head>
<body>
<div class="weui-toptips weui-toptips_warn js_tooltips weui-icon-warn" id="errTip" style="display: none;">错误提示</div>
<div class="weui-toptips weui-toptips_warn weui-toptips_success weui-icon-success js_tooltips" id="successTip" style="display: none;">注册成功</div>
    <div class="weui-tab">
        <div class="weui-tab__panel">
            <div class="weui-cells weui-cells_form">
                <div class="weui-cell">
                    <div class="weui-cell__hd">
                        <label class="weui-label">手机号</label>
                    </div>
                    <div class="weui-cell__bd">
                        <input type="number" id="txtMobile" class="weui-input" required placeholder="请输入手机号">
                    </div>
                </div>
                <div class="weui-cell">
                    <div class="weui-cell__hd">
                        <label class="weui-label">姓名</label>
                    </div>
                    <div class="weui-cell__bd">
                        <input type="text" id="txtName" class="weui-input" required placeholder="请输入姓名">
                    </div>
                </div>
                <div class="weui-cell">
                    <div class="weui-cell__hd">
                        <label class="weui-label">邮箱</label>
                    </div>
                    <div class="weui-cell__bd">
                        <input type="email" id="txtEmail" class="weui-input" required placeholder="请输入邮箱">
                    </div>
                </div>
                <div class="weui-cell">
                    <div class="weui-cell__hd">
                        <label class="weui-label">密码</label>
                    </div>
                    <div class="weui-cell__bd">
                        <input type="password" id="txtPwd" class="weui-input" required placeholder="请输入密码">
                    </div>
                </div>
                <div class="weui-cell">
                    <div class="weui-cell__hd">
                        <label class="weui-label">确认密码</label>
                    </div>
                    <div class="weui-cell__bd">
                        <input type="password" id="txtRePwd" class="weui-input" required placeholder="请再次输入密码">
                    </div>
                </div>
                <div class="weui-cell">
                    <div class="weui-cell__hd">
                        <label class="weui-label">地址</label>
                    </div>
                    <div class="weui-cell__bd">
                    	<div class="weui-flex">
                    		<div class="weui-flex__item">
                    			<select class="weui-select" name="province" id="selP"></select>
                    		</div>
                    		<div class="weui-flex__item">
                    			<select class="weui-select" name="city" id="selC"></select>
                    		</div>
                    		<div class="weui-flex__item">
                    			<select class="weui-select" name="area" id="selA"></select>
                    		</div>
                    	</div>
                    </div>
                </div>
                <div class="weui-cell">
                    <div class="weui-cell__hd">
                        <label class="weui-label">详细地址</label>
                    </div>
                    <div class="weui-cell__bd">
                        <input type="text" id="txtAddress" class="weui-input" required placeholder="请再次输入详细地址">
                    </div>
                </div>
            </div>
            <div class="weui-btn-area">
                <div class="weui-btn weui-btn_primary" id="btnReg">注册</div>
            </div>
        </div>
        {{include '../shared/_footer_nav'}}
    </div>
    {{include '../shared/_bottom'}}
    <script src="/js/PCASClass.js"></script>
    <script>
    	new PCAS("province","city","area");
		var regMobile = /^1[3857]{1}\d{9}$/
		var regEmail = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/
		$('#btnReg').click(function(){
			var mobile = $('#txtMobile').val().trim()
			var email = $('#txtEmail').val().trim()
			var name = $('#txtName').val().trim()
			var pwd = $('#txtPwd').val().trim()
			var rePwd = $('#txtRePwd').val().trim()
			var selP = $('#selP').val()
			var selC = $('#selC').val()
			var selA = $('#selA').val()
			var address = $('#txtAddress').val().trim()
		    if(!regMobile.test(mobile)){
		        showTip("errTip","手机号码格式错误")
		        return false
		    }
		    if(name==""){
		    	showTip("errTip","姓名不能为空")
		    	return false
		    }
		    if(!regEmail.test(email)){
		    	showTip("errTip","邮箱格式错误")
		    	return false
		    }
		    if(pwd){
		    	if(pwd.length<6){
		    		showTip("errTip","密码不能小于六位")
		    		return false
		    	}
		    }
		    else{
		    	showTip("errTip","密码不能为空")
		    	return false
		    }
		    if(rePwd){
		    	if(rePwd!=pwd){
		    		showTip("errTip","两次输入密码不一致")
		    		return false
		    	}
		    }
		    else{
		    	showTip("errTip","请再次输入密码")
		    	return false
		    }
		    if(selP=="" || selC=="" ||selA==""){
		    	showTip("errTip","请选择省市区县数据")
		    	return false
		    }
		    if(address==""){
		    	showTip("errTip","请输入详细地址信息")
		    	return false
		    }
		    $.ajax({
		    	url:'/reg',
		    	method:'post',
		    	data:{mobile:mobile,name:name,pwd:pwd,email:email,address:`${selP}-${selC}-${selA}-${address}`},
		    	error:function(err){
		    		console.log(err)
		    	},
		    	success:function(res){
		    		if(res.status=="y"){
		    			showTip("successTip",res.msg)
		    		}
		    		else{
		    			showTip("errTip",res.msg)
		    		}
		    	}
		    })
		})
		function showTip(tag,msg){
		    var $tip = $("#"+tag)
		    $tip.text(msg)
		    $tip.show()
		    setTimeout(function(){
		        $tip.hide()
		    },3000)
		}
    </script>
</body>
</html>